package pairs;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		try {
			int N = in.nextInt(), K = in.nextInt();
			Map<Integer, Integer> count = new HashMap<Integer, Integer>();
			int n = 0;
			for(int i = 0; i < N; i++) {
				int num = in.nextInt();
				Integer obj1 = count.get(num - K);
				Integer obj2 = count.get(num + K);
				n += (obj1 == null ? 0 : obj1.intValue()) + (obj2 == null ? 0 : obj2.intValue());
				Integer obj = count.get(num);
				count.put(num, (obj == null ? 0 : obj.intValue()) + 1);
			}
			System.out.println(n);
		} finally {
			in.close();
		}
	}
}
